﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    using DAL.Entities;

    public class TaiKhoanDAL : BaseDAL, UTL.IBaseDAL
    {
        public int Count()
        {
            throw new NotImplementedException();
        }

        public DataTable Select()
        {
            string sql = @"SELECT * from taikhoan a join nhanvien b on a.ma_nv=b.ma_nv";
            return ExecuteQuery(sql);
        }

        public DataTable Select(object obj)
        {
            throw new NotImplementedException();
        }

        public object GetByKey(object key)
        {
            throw new NotImplementedException();
        }

        public bool Delete(string id)
        {
            string sql = @" DELETE FROM taikhoan WHERE taikhoan = '{0}' ";
            sql = string.Format(sql,id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Insert(object obj)
        {
            var o = (Tai_Khoan)obj;
            string sql = @"INSERT INTO taikhoan(taikhoan,matkhau,ma_nv) VALUES('{0}','{1}','{2}')";
            sql = string.Format(sql,o.taikhoan,o.matkhau,o.manv);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            var o = (Tai_Khoan)obj;
            string sql = @"UPDATE taikhoan SET matkhau='{0}',ma_nv='{1}' WHERE taikhoan='{2}' ";
            sql = string.Format(sql,o.matkhau,o.manv,o.taikhoan);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public DataTable Search(string name)
        {
            throw new NotImplementedException();
        }

        public DataTable select_nhanvien()
        {
            string sql = @" SELECT ma_nv as id, ten_nv as ten FROM nhanvien ";
            return ExecuteQuery(sql);
        }

    }
}
